<?php

/**
 * Subclass for representing a row from the 'blog_info' table.
 *
 * 
 *
 * @package lib.model
 */ 
class BlogInfo extends BaseBlogInfo
{
    public static function getThemesCssList()
    {
        $ar = array('eshop' => sfContext::getInstance()->getI18n()->__('default')
                    , 'red' => sfContext::getInstance()->getI18n()->__('red')
                    ,  'img' => sfContext::getInstance()->getI18n()->__('with image'));
        foreach ($ar as $key => $theme )
        {
            if( file_exists(sfConfig::get('sf_web_dir') . '/css/' . $key . '.css') )
            {
                $arReturn[$key] = $theme;
            }
        }
        return $arReturn;
    }
    public static function getOrderselectionList()
    {
         return array( 1 => sfContext::getInstance()->getI18n()->__('By date ascending')
                    , 2 => sfContext::getInstance()->getI18n()->__('By date descending')
                    , 3 => sfContext::getInstance()->getI18n()->__('By Priority'));
    }
    public static function addCriteriaByOrder($c)
    {
         return array( 1 => $c->addAscendingOrderByColumn(BlogPeer::CREATED_AT)
                    , 2 => addDescendingOrderByColumn(BlogPeer::CREATED_AT)
                    , 3 => addDescendingOrderByColumn(BlogPeer::PRIORITY));
    }
    public function BlogInfo( )
    {
        $this->setUserId(get_user_id());
//        method used for getting info, if user not logged in
//        if($this->user_id < 1)
//        {
//            return;
//        }
        $this->setCssName('eshop');
        $this->setTitle(sfContext::getInstance()->getI18N()->__('Interateitis blog'));
        $this->setOrderBy(2);
        $this->setBlogsCount(count(Blog::getActivePostsByUser($this->user_id)));
        $this->setInterfaceLng(sfContext::getInstance()->getUser()->getCulture());
        $this->setPaginateBy(10);
        $this->setStatusId(MyConstants::STATUS_APPROVED);
        return $this;
    }
    /**
     * 
     * returns blogInfo by user id
     * @param int $id - user id
     * @return BlogId obj (null if not found)
     */
    public static function getBlogInfoByUser($id)
    {
        $c = new Criteria();
        $c->add(BlogInfoPeer::USER_ID, $id);
        $c->add(BlogInfoPeer::STATUS_ID, MyConstants::STATUS_APPROVED);
        $blogInfo = BlogInfoPeer::doSelectOne($c);
        return $blogInfo;
    }
    
    public function getPhotos()
    {
        return Files::getByObj(MyConstants::TYPE_BLOG_PROFILE, $this->id);
    }
    public function getFirstPhotos($cout)
    {
        $c = new Criteria();
        $c->add(FilesPeer::OBJ_TYPE, MyConstants::TYPE_BLOG_PROFILE);
        $c->add(FilesPeer::OBJ_ID, BlogUserInfo::getInstance()->getBlogInfo()->getId());
        $c->addDescendingOrderByColumn(FilesPeer::PRIORITY);
        $c->setLimit($cout);
        $f = FilesPeer::doSelect($c);
        
        return $f;
    }
}
